package org.hxd.client.user.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.hxd.pojo.Orderitem;
import org.hxd.pojo.Orders;
import org.hxd.pojo.User;

import java.util.List;

public interface UserDao {
    @Insert("insert into user(username,password,email,gender,telephone,introduce,activeCode) " +
            "values(#{username},#{password},#{email},#{gender},#{telephone},#{introduce},#{activeCode})")
    int addUser(User user);

    @Update("update user set state = 1 where activeCode = #{activeCode}")
    int activeUser(String activeCode);

    @Select("select count(id) from user where email = #{email}")
    int findmail(String email);

    @Select("select count(id) from user where username = #{username}")
    int findusername(String username);

    @Select("select * from user where username=#{username} and password=#{password}")
    User findUserByLogin(User user);

    @Update("update user set password = #{password},gender = #{gender},telephone = #{telephone} where id = #{id}")
    int modifyUser(User user);

    List<Orders> findOrderByUser(Integer id);

    List<Orderitem> findOrderitemById(String id);

    @Delete("delete from orders where id = #{id}")
    void deleteOrderById(String id);

    @Delete("delete from orderitem where order_id = #{id}")
    void deleteOrderItemById(String id);

    @Update("update products set pnum = pnum + #{buynum} where id = #{products.id}")
    void updatepnum(Orderitem item);
}
